var dqfl = "UI,输入";
var theme_list_open = false;

$(document).ready(function () {
    function fixHeight() {
        var headerHeight = $("#switcher").height();
        $("#iframe").attr("height", $(window).height() - 54 + "px");
    }

    $(window).resize(function () {
        fixHeight();
    }).resize();

    $(".icon-monitor").addClass('active');

    $(".icon-mobile-3").click(function () {
        $("#by").css("overflow-y", "auto");
        $('#iframe-wrap').removeClass().addClass('mobile-width-3');
        $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
        $(this).addClass('active');
        return false;

    });

    $(".icon-mobile-2").click(function () {
        $("#by").css("overflow-y", "auto");
        $('#iframe-wrap').removeClass().addClass('mobile-width-2');
        $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
        $(this).addClass('active');
        return false;
    });


    $(".icon-mobile-1").click(function () {
        $("#by").css("overflow-y", "auto");
        $('#iframe-wrap').removeClass().addClass('mobile-width');
        $('.icon-tablet,.icon-mobile,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
        $(this).addClass('active');
        return false;
    });

    $(".icon-tablet").click(function () {
        $("#by").css("overflow-y", "auto");
        $('#iframe-wrap').removeClass().addClass('tablet-width');
        $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
        $(this).addClass('active');
        return false;
    });

    $(".icon-monitor").click(function () {
        $("#by").css("overflow-y", "hidden");
        $('#iframe-wrap').removeClass().addClass('full-width');
        $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
        $(this).addClass('active');
        return false;
    });

    if (dqfl.indexOf("APP模板") != -1) {
        $("#by").css("overflow-y", "auto");
        $('#iframe-wrap').removeClass().addClass('mobile-width-2');
        $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
        $(this).addClass('active');
        return false;
    }
});

function Responsive($a) {
    if ($a == true) $("#Device").css("opacity", "100");
    if ($a == false) $("#Device").css("opacity", "0");
    $('#iframe-wrap').removeClass().addClass('full-width');
    $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
    $(this).addClass('active');
    return false;
};


//millde javascript
var canGetCookie = 0;//是否支持存储Cookie 0 不支持 1 支持
var ajaxmockjax = 1;//是否启用虚拟Ajax的请求响 0 不启用  1 启用
//默认账号密码

var truelogin = "Sailor";
var truepwd = "123";

var CodeVal = 0;
Code();

function Code() {
    if (canGetCookie == 1) {
        createCode("AdminCode");
        var AdminCode = getCookieValue("AdminCode");
        showCheck(AdminCode);
    } else {
        showCheck(createCode(""));
    }
}

function showCheck(a) {
    CodeVal = a;
    var c = document.getElementById("myCanvas");
    var ctx = c.getContext("2d");
    ctx.clearRect(0, 0, 1000, 1000);
    ctx.font = "80px 'Hiragino Sans GB'";
    ctx.fillStyle = "#E8DFE8";
    ctx.fillText(a, 0, 100);
}

$(document).keypress(function (e) {
    // 回车键事件
    if (e.which == 13) {
        $('input[type="button"]').click();
    }
});
//粒子背景特效
$('body').particleground({
    dotColor: '#E8DFE8',
    lineColor: '#133b88'
});
$('input[name="pwd"]').focus(function () {
    $(this).attr('type', 'password');
});
$('input[type="text"]').focus(function () {
    $(this).prev().animate({'opacity': '1'}, 200);
});
$('input[type="text"],input[type="password"]').blur(function () {
    $(this).prev().animate({'opacity': '.5'}, 200);
});
$('input[name="login"],input[name="pwd"]').keyup(function () {
    var Len = $(this).val().length;
    if (!$(this).val() == '' && Len >= 5) {
        $(this).next().animate({
            'opacity': '1',
            'right': '30'
        }, 200);
    } else {
        $(this).next().animate({
            'opacity': '0',
            'right': '20'
        }, 200);
    }
});
var open = 0;
layui.use('layer', function () {
    var msgalert = '默认账号:' + truelogin + '<br/> 默认密码:' + truepwd;
    //非空验证
    $('input[type="button"]').click(function () {
        var login = $('input[name="login"]').val();
        var pwd = $('input[name="pwd"]').val();
        var code = $('input[name="code"]').val();
        if (login == '') {
            ErroAlert('请输入您的账号');
        } else if (pwd == '') {
            ErroAlert('请输入密码');
        } else if (code == '' || code.length != 4) {
            ErroAlert('输入验证码');
        } else {
            //认证中..
            fullscreen();
            $('.login').addClass('test'); //倾斜特效
            setTimeout(function () {
                $('.login').addClass('testtwo'); //平移特效
            }, 300);
            setTimeout(function () {
                $('.authent').show().animate({right: -320}, {
                    easing: 'easeOutQuint',
                    duration: 600,
                    queue: false
                });
                $('.authent').animate({opacity: 1}, {
                    duration: 200,
                    queue: false
                }).addClass('visible');
            }, 500);

            //登陆
            var JsonData = {login: login, pwd: pwd, code: code};
            //此处做为ajax内部判断
            var url = "";
            if (JsonData.login == truelogin && JsonData.pwd == truepwd && JsonData.code.toUpperCase() == CodeVal.toUpperCase()) {
                url = "Ajax/Login";

            } else {
                url = "Ajax/LoginFalse";
            }


            AjaxPost(url, JsonData,
                function () {
                    //ajax加载中
                },
                function (data) {
                    //ajax返回
                    //认证完成
                    setTimeout(function () {
                        $('.authent').show().animate({right: 90}, {
                            easing: 'easeOutQuint',
                            duration: 600,
                            queue: false,
                        });
                        $('.authent').animate({opacity: 0}, {
                            duration: 200,
                            queue: false
                        }).addClass('visible');
                        $('.login').removeClass('testtwo'); //平移特效
                    }, 2000);
                    setTimeout(function () {
                        $('.authent').hide();
                        $('.login').removeClass('test');
                        if (data.Status == 'ok') {
                            //登录成功
                            $('.login div').fadeOut(100);
                            $('.success').fadeIn(1000);
                            $('.success').html(data.Text);
                            //跳转操作

                        } else {
                            AjaxErro(data);
                        }
                    }, 2400);
                })
        }
    })
})
var fullscreen = function () {
    elem = document.body;
    if (elem.webkitRequestFullScreen) {
        elem.webkitRequestFullScreen();
    } else if (elem.mozRequestFullScreen) {
        elem.mozRequestFullScreen();
    } else if (elem.requestFullScreen) {
        elem.requestFullscreen();
    } else {
        //浏览器不支持全屏API或已被禁用
    }
}
if (ajaxmockjax == 1) {
    $.mockjax({
        url: 'Ajax/Login',
        status: 200,
        responseTime: 50,
        responseText: {
            "Status": "ok", "Text": "<script>window.top.location = 'http://localhost:63342/FriendsSpace/templates/base/index.html?_ijt=744c2t9h6cehtem0o7mflf15uv';</script>",

        }

    });
    $.mockjax({
        url: 'Ajax/LoginFalse',
        status: 200,
        responseTime: 50,
        responseText: {"Status": "Erro", "Erro": "账号名或密码或验证码有误"}
    });


}


// register script

$('input[type="submit"]').click(function () {
    var login = $('input[name="loginR"]').val();
    var pwd2 = $('input[name="pwd2R"]').val();
    var pwd = $('input[name="pwd1R"]').val();
    var tel = $('input[name="telNumberR"]').val();
    var code = $('input[name="codeR"]').val();
    var JsonDataR = {login: login, pwd: pwd, tel: tel, code: code,};
    //此处做为ajax内部判断
    var url = "";
      if ( JsonData.code.toUpperCase() == "2345") {
                url = "Ajax/Register";

            } else {
                url = "Ajax/RegisterFalse";
            }
    AjaxPost(url, JsonDataR,
        function () {
            //ajax加载中
        },
        function (data) {
        })
})

if (ajaxmockjax == 1) {
    $.mockjax({
        url: 'Ajax/Register',
        status: 200,
        responseTime: 50,
        responseText: {
            "Status": "ok", "Text": "注册成功<script>window.top.location = 'http://localhost:63342/FriendsSpace/templates/base/index.html?_ijt=744c2t9h6cehtem0o7mflf15uv';</script>",

        }

    });
    $.mockjax({
        url: 'Ajax/RehisterFalse',
        status: 200,
        responseTime: 50,
        responseText: {"Status": "Erro", "Erro": "注册出错"}
    });


}

function vUsename() {
    var login = $('input[name="loginR"]').val();
    var re = /^[a-zA-Z_]{6,18}$/;
    if (login == "") {
        ErroAlert("请输入用户名");
    } else if (login.length < 6 || login.length > 18) {
        ErroAlert("格式错误,长度应为6-18个字符");
    } else if (!re.test(login)) {

        ErroAlert("格式错误,只能包含英文字母和下划线");
    }

}


function vPassword() {
    var pwd2 = $('input[name="pwd2R"]').val();
    var pwd = $('input[name="pwd1R"]').val();
    var re = /^(?=.*\d)(?=.*[a-zA-Z])[\da-zA-Z]{6,}$/;
    // var reg=/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/;

    if (pwd == "") {
        ErroAlert('请输入密码');

    } else if (pwd.length < 6) {
        ErroAlert('格式错误,,密码长度至少为6位');
    } else if (!re.test(pwd)) {
        ErroAlert('格式错误,必须包含英文字母大小写和数字');

    }
}

function vPassword1() {
    var pwd2 = $('input[name="pwd2R"]').val();
    var pwd = $('input[name="pwd1R"]').val();
    if (pwd2 == '' || pwd != pwd2) {
        ErroAlert('请二次确认密码');
    }
}


function vTel() {
    var tel = $('input[name="telNumberR"]').val();

    var re = /^1\d{10}$/;
    if (tel == "") {
        ErroAlert("请输入联系电话");
    } else if (!re.test(tel)) {
        ErroAlert("电话格式输入错误");
    }
}

function vCode() {
    var code = $('input[name="codeR"]').val();
    if (code == '' || code.length != 4) {
        ErroAlert('输入正确的验证码');
    }

}




